import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import { getGoodsSelector } from '@/api/services/goods'
export default {
  components: {},
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      list: [],
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: 'createTime'
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    /*this.$store.dispatch('base/getDictionaryData', { sort: 'sex' }).then(res => {
      this.genderOptions = res
    });
    this.$store.dispatch("base/getDictionaryData", { sort: "Brand" }).then((res) => {
      this.brandOptions = res;
    });*/
  },
  mounted() {},
  methods: {
    handleCommandDown (command) {
      window.open(command)
    },
    objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0 || columnIndex === 4  || columnIndex === 5 || columnIndex === 6 ) {
        if (row.rowIndex > 0) {
          return {
            rowspan: row.rowIndex,
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },
    goBack() {

      this.$emit('refresh')
    },
    getGroupDetails (data, list) {
      for (let i = 0; i < data.length; i++) {
        if (list.length === 0) {
          list.push({
            id: data[i].id,
            children: [
              data[i]
            ]
          })
        } else {
          let bl = false
          for (let j = 0; j < list.length; j++) {
            if (data[i].id === list[j].id) {
              bl = true
              list[j].children.push(data[i])
            }
          }
          if (!bl) {
            list.push({
              id: data[i].id,
              children: [
                data[i]
              ]
            })
          }
        }
      }
    },
    getData() {
      this.loading = true
      this.list = []
      let _query = {
        ...this.listQuery
      }
      let query = {}
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join()
        } else {
          query[key] = _query[key]
        }
      }
      request({
        url: `api/campus/${this.id}/history`,
        method: 'get',
        data: {
          ...this.listQuery
        }
      }).then(res => {
        this.list = res.data.list
        this.total = res.data.pagination.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    init(id) {
      this.visible = true
      this.id = id
      this.getData()
    },
  }
}
